#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = "HuJiang";

from django.db import models;
import datetime;

'''
Account 模块 entity 定义
'''

class User(models.Model):
    # ---- 主键列 ----
    id = models.AutoField(primary_key=True);
    # ---- 非主键列 ----
    user_name = models.CharField(name="user_name", max_length=255, blank = False, null = False);
    password = models.CharField(name="password", max_length=255, blank = False, null = False);
    age = models.IntegerField(name="age", default=18);
    email = models.CharField(name="email", max_length=255, blank = True, null = True);
    create_date = models.DateTimeField(auto_now=True, blank = True, null = True);

    def user_dict(self):
        user_dict = {};
        user_dict["id"] = self.id;
        user_dict["userName"] = self.user_name;
        user_dict["password"] = self.password;
        user_dict["email"] = self.email;
        user_dict["age"] = self.age;
        if self.create_date:
            user_dict["createDate"] = self.create_date.strftime("%Y-%m-%d %H:%M:%S");
        return user_dict;

    # 指定表名，若不指定，默认生成表名为：app名称_类名，比如account_user
    class Meta:
        db_table = ('account_user')







